package com.hqj.service;

import com.hqj.dao.AgreementDao;
import com.hqj.dao.FilesDao;
import com.hqj.entity.Agreement;
import com.hqj.entity.Files;
import com.hqj.util.ReturnValueUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AgreementServiceI implements BaseService<Agreement> {

    @Autowired
    private AgreementDao ad;
    @Resource(name="fileServiceI")
    private FileServiceI fsi;

    @Override
    public List<Agreement> find(Agreement agreement) {
        List<Agreement> list = ad.find(agreement);
        return list;
    }

    @Override
    public Agreement get(Agreement agreement) {
        List<Agreement> list = ad.find(agreement);
        agreement = list.size()>0?list.get(0):null;
        if(agreement!=null){
            long agreementId = agreement.getAgreementId();
            String tabName = "t_agreement";
            Files fs = new Files();
            fs.setTabId(agreementId+"");fs.setTabName(tabName);
            List<Files> ls = fsi.find(fs);
            agreement.setList(ls);
        }
        return agreement;
    }

    @Override
    public Map<String, Object> add(Agreement agreement) {
        int i = ad.add(agreement);
        return ReturnValueUtil.aer(i,"新增");
    }

    @Override
    public Map<String, Object> edit(Agreement agreement) {
        return null;
    }

    @Override
    public Map<String, Object> remove(int id) {
        return null;
    }
}
